package com.zhu.char06

/**
 *
 * @version 1.0
 * @author study
 * @date 2020/9/3 17:30
 *
 */
object Scala_Singleton {
  def main(args: Array[String]): Unit = {

    val stu = Student16.getInstance()
    println(stu)

    val stu2 = Student16.getInstance()
    println(stu2)
  }
}

//懒汉式
/*object Student16 {
  private var s: Student16 = null

  def getInstance(): Student16 = {
    if (s == null) {
      s = new Student16;
    }
    s
  }
}*/
//饿汉式
object Student16 {
  private var s: Student16 = new Student16

  def getInstance(): Student16 = {
    s
  }
}

//主构造方法私有化
class Student16 private {}
